--体验魔尊战场
--#include "data\config\exep\ExepMoZunConfig.lua" once

EXEPMOZUN_FUBEN_KILLMON_NUM		= 1 			--击杀怪物数量
EXEPMOZUN_FUBEN_MY_RANK_IDX		= 2 			--我的名次

--[[
注册一些事件
]]
function ResisterExepMoZunProc()
	--print("ResisterExepMoZunProc...")
	SceneEnterDispatcher.register( ExepMoZunConfig.sceneId, OnEnterExepMoZun )
	SceneHandExitDispatcher.register( ExepMoZunConfig.sceneId,  OnCommonSceneHandExit )		--注册手工离开场景、副本时触发的事件（先执行）
	FubenExitDispatcher.register( ExepMoZunConfig.fubenId,  OnExepMoZunExit )			--注册离开场景、副本后触发的事件（后执行）
end

--[[
已经退出副本
注意：手工退出、下线、被T出，GM指令Move出都会触发
]]
function OnExepMoZunExit( sysarg, fubenId, sceneId )
	--print("OnExepMoZunExit, fubenId="..fubenId)
	if Actor.hasBuffById( sysarg, ExepMoZunConfig.initBuffId ) then
		Actor.delBuffById( sysarg, ExepMoZunConfig.initBuffId )
	end
	ClearActorAllBuffs( sysarg, ExepMoZunConfig.killAddBuffs )
end


function EnterExepMoZun( sysarg )
	--print("EnterExepMoZun, ...")
	CommonEnterScence( sysarg, ExepMoZunConfig, 0, "", nil, nil ) 
end

--[[
已经进入体验魔尊战场、盟重杀神
]]
function OnEnterExepMoZun( sysarg, sceneId, lastSceneId )
	--print("OnEnterExepMoZun, sceneId="..sceneId)
	local fubenHandle 	= Actor.getFubenHandle( sysarg )
	local fubenPtr 		= Actor.getFubenPrt( sysarg )
	FreshCommonMonsters( ExepMoZunConfig.monsters, fubenHandle, true )
	Fuben.setFbValue( fubenPtr, EXEPMOZUN_FUBEN_KILLMON_NUM, 0 )
	Fuben.setFbValue( fubenPtr, EXEPMOZUN_FUBEN_MY_RANK_IDX, ExepMoZunConfig.initRankIdx )

	if not Actor.hasBuffById( sysarg, ExepMoZunConfig.initBuffId ) then
		Actor.addBuffById( sysarg, ExepMoZunConfig.initBuffId )
		--print("OnEnterExepMoZun, addbuff="..ExepMoZunConfig.initBuffId)
	end
	InitExepMoZunPanel( sysarg )
end

function InitExepMoZunPanel( sysarg )
	local fubenPtr 		= Actor.getFubenPrt( sysarg )
	local contStyle 	= 9					--排名（非来自于排行榜）
	local buttons 		= {1}
	local activityId 	= enRightPanelActivity_ExepMoZun
	local title			= Lang.ScriptTips.MoZunPanel001

	local bossCfg 	= {}
	bossCfg.myRankIdx	= Fuben.getFbValue( fubenPtr, EXEPMOZUN_FUBEN_MY_RANK_IDX )
	--print("OnEnterExepMoZun, myRankIdx="..bossCfg.myRankIdx)
	OpenCommonStylePanel( sysarg, 1, activityId, 0, title, bossCfg, contStyle, buttons  )
end

function ChangeExepMoZunPanel( sysarg, myRankIdx )
	local activitySts 	= 1
	local contStyle 	= 9
	local buttons1 		= {1}
	local buttons2 		= {1}
	local bossCfg 	= {}
	bossCfg.myRankIdx	= myRankIdx
	ChangeCommonStylePanel( sysarg, activitySts, contStyle, bossCfg, buttons1, buttons2 )
end

--[[
--sysarg:归属玩家
--lastHitKiller：最后一击玩家
注意：怪物死亡时，玩家可能不在线，要确保副本进度能够继续进行
]]
function OnExepMoZunBossDie( monster, sysarg, monId, lastHitKiller )
	--print("OnExepMoZunBossDie, monId="..monId)
	local fubenPtr 	= Actor.getFubenPrt( monster )
	local killNum 	= Fuben.getFbValue( fubenPtr, EXEPMOZUN_FUBEN_KILLMON_NUM )
	local newKillNum= killNum + 1
	Fuben.setFbValue( fubenPtr, EXEPMOZUN_FUBEN_KILLMON_NUM, newKillNum )

	local newRankIdx 	= Fuben.getFbValue( fubenPtr, EXEPMOZUN_FUBEN_MY_RANK_IDX ) - 1
	if newRankIdx <= 1 then
		newRankIdx = 1
	end

	ChangeExepMoZunPanel( sysarg, newRankIdx )
	Fuben.setFbValue( fubenPtr, EXEPMOZUN_FUBEN_MY_RANK_IDX, newRankIdx )

	local buffId = ExepMoZunConfig.killAddBuffs[newKillNum]
	if buffId then
		ClearActorAllBuffs( sysarg, ExepMoZunConfig.killAddBuffs )
		Actor.addBuffById( sysarg, buffId )
	end 		--通关成功

	if newRankIdx <= 1 then 			--夺取了第一名
		GiveCommonAward( sysarg, ExepMoZunConfig.awards, GameLog.clExepMoZunAward, "exep mozun" )
		local panelInfo 	= {}
		panelInfo.sts 		= 1 				
		panelInfo.awards 	= ExepMoZunConfig.awards
		PassActivityRightPanel( sysarg, 1, enRightPanelActivity_ExepMoZun, panelInfo )
	end
end


ResisterExepMoZunProc()

